import pypinyin

def convert_to_pinyin(input_file, output_file):
    with open(input_file, 'r', encoding='utf-8') as infile, open(output_file, 'w', encoding='utf-8') as outfile:
        for line in infile:
            line = line.strip()
            if line:
                pinyin_line = ' '.join(pypinyin.lazy_pinyin(line))#将空格作为分隔符，将拼音拼接成字符串
                outfile.write(pinyin_line + '\n')

if __name__ == "__main__":
    input_file = 'pinyin.txt'
    output_file = 'pinyin_output.txt'
    convert_to_pinyin(input_file, output_file)